package com.goodving.guli.bt.ui;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.goodving.guli.R;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.weight.UserInfo;

import java.util.Iterator;
import java.util.List;

import cn.com.smartdevices.bracelet.chart.util.C0804t;

public class WeightUserQuickPicker extends FrameLayout {
    private static final int f10850a = 6;
    private RecyclerView f10851b;
    private ac f10852c;
    private LinearLayoutManager f10853d;
    private int f10854e;
    private ab f10855f;
    private int f10856g;
    private boolean f10857h;

    public WeightUserQuickPicker(Context context) {
        this(context, null, 0);
    }

    public WeightUserQuickPicker(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }



    class aa extends RecyclerView.ItemDecoration { // C0548U
        final /* synthetic */ WeightUserQuickPicker f10864a;

        aa(WeightUserQuickPicker weightUserQuickPicker) {
            this.f10864a = weightUserQuickPicker;
        }

        public void getItemOffsets (Rect rect, View view, RecyclerView recyclerView, RecyclerView.State agVar) {// m15414a
            rect.left = this.f10864a.f10854e;
            rect.top = 0;
            rect.bottom = 0;
            rect.right = this.f10864a.f10854e;
        }
    }

    public WeightUserQuickPicker(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        inflate(context, R.layout.view_weight_user_picker, this);
        this.f10851b = (RecyclerView) findViewById(R.id.user_list);
        this.f10851b.setHasFixedSize(true); // m5362a
        this.f10853d = new LinearLayoutManager(context, 0, false);
        this.f10851b.setLayoutManager(this.f10853d); // m5354a
        this.f10854e = getResources().getDimensionPixelSize(R.dimen.statistic_weight_user_picker_item_padding);
        this.f10851b.addItemDecoration(new aa(this)); // m5352a
        this.f10851b.setHorizontalFadingEdgeEnabled(true);
        this.f10851b.setFadingEdgeLength(this.f10854e * 3);
    }

    public class ae extends RecyclerView.ViewHolder { // aj
        protected WeightUserAvatar f10870r;

        public ae(View view) {
            super(view);
            this.f10870r = (WeightUserAvatar) view.findViewById(R.id.user_avatar);
        }
    }

    class ad implements OnClickListener {
        final /* synthetic */ UserInfo f10867a;
        final /* synthetic */ int f10868b;
        final /* synthetic */ ac f10869c;

        ad(ac acVar, UserInfo userInfo, int i) {
            this.f10869c = acVar;
            this.f10867a = userInfo;
            this.f10868b = i;
        }

        public void onClick(View view) {
            if (this.f10869c.f10865a.f10855f != null) {
                this.f10869c.f10865a.f10855f.m14727a(view, this.f10867a, this.f10868b);
            }
        }
    }

    class ac extends RecyclerView.Adapter<ae> { // C0541N
        final /* synthetic */ WeightUserQuickPicker f10865a;
        private List<UserInfo> f10866b;

        public ac(WeightUserQuickPicker weightUserQuickPicker, List<UserInfo> list) {
            this.f10865a = weightUserQuickPicker;
            this.f10866b = list;
        }

        public int getItemCount () { // m15416a
            return this.f10866b.size();
        }

        public /* synthetic */ ae onCreateViewHolder (ViewGroup viewGroup, int i) { // m15417a
            return m15420c(viewGroup, i);
        }

        public void onBindViewHolder (ae aeVar, int i) { // m15419a
            UserInfo userInfo = (UserInfo) this.f10866b.get(i);
            aeVar.f10870r.setImageResource(R.drawable.choose_user_src_selector);
            aeVar.f10870r.m15375a(userInfo.name);
            Utils.m8008a(userInfo, aeVar.f10870r);
            if (this.f10865a.f10856g == i) {
                aeVar.f10870r.setAlpha(1.0f);
            } else {
                aeVar.f10870r.setAlpha(0.3f);
            }
            aeVar.f10870r.setOnClickListener(new ad(this, userInfo, i));
        }

        public ae m15420c(ViewGroup viewGroup, int i) {
            return new ae(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.view_weight_user_picker_item, viewGroup, false));
        }
    }

    public void m15379a(int i) {
        this.f10856g = i;
        this.f10852c.notifyDataSetChanged(); // m5221d
    }

//    public void m15380a(int i, int i2) {
//        this.f10856g = i;
//        this.f10852c.m5217c(i2);
//        this.f10852c.m5217c(this.f10856g);
//    }

    public void m15381a(ab abVar) {
        this.f10855f = abVar;
    }

    public void m15382a(List<UserInfo> list) {
        this.f10852c = new ac(this, list);
        // this.f10851b.m5349a(this.f10852c);
        this.f10851b.setAdapter(this.f10852c);

    }

    public boolean m15383a() {
        return this.f10857h;
    }

    public void m15384b() {
        if (this.f10852c.getItemCount() > 1) {
            int childCount = this.f10851b.getChildCount();
            float f = -C0804t.m8825a(getContext(), 50.0f);
            for (int i = 0; i < childCount; i++) {
                View childAt = this.f10851b.getChildAt(i);
                childAt.setTranslationX(((float) i) * f);
                if (i != childCount - 1) {
                    childAt.setAlpha((((float) i) * 0.08f) + 0.3f);
                }
            }
            this.f10857h = true;
        }
    }

    public void m15385b(int i) {
        Iterator it = this.f10852c.f10866b.iterator();
        int i2 = 0;
        while (it.hasNext() && ((UserInfo) it.next()).uid != i) {
            i2++;
        }
        m15379a(i2);
        if (i2 >= f10850a) {
            this.f10853d.scrollToPosition(i2);
        }
    }

    public void m15386c() {
        if (this.f10852c.getItemCount() > 1) {
            int childCount = this.f10851b.getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childAt = this.f10851b.getChildAt(i);
                childAt.setTranslationX(0.0f);
                childAt.setAlpha(1.0f);
            }
            this.f10857h = false;
        }
    }
}
